﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_DishSrhForm
 * 类型：       控制层
 * 功能说明：   菜肴信息列表页面
 * 作者：       黄鑫
 * 创建日期：   2008/01/07
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using log4net;
using Shpm.App.Commons.Utils;
using Shpm.App.Master.Dao;
using Shpm.App.Master.Bean;


public partial class App_Input_DishSrhForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_DishSrhForm));

    private const string SELECT_ALL = "-1";

    // page load
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!Page.IsPostBack)
        {
            // 取得当前登录的用户id信息
            SysUserManager manager = new SysUserManager(Context);
            SysUserBean sysUserBean = manager.getSysUserBean();
            MstSysUserBean mstSysUserBean =
                sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
            MstEmployeeBean mstEmpBean =
                sysUserBean == null ? null : sysUserBean.getEmployeeBean();

            initPageControls();

            // 接收传递参数为分页编号
            if (Context.Items.Contains("ParamPageIndex"))
            {
                viewSrhRst.PageIndex = Convert.ToInt32(Context.Items["ParamPageIndex"]);
            }
            if (Context.Items.Contains("CMB_TIME"))
            {
                this.ViewState["TIME"] = Convert.ToString(Context.Items["CMB_TIME"]);
                lstDishTime.SelectedValue = Convert.ToString(this.ViewState["TIME"]);
            }
            if (Context.Items.Contains("CMB_CLASS"))
            {
                this.ViewState["CLASS"] = Convert.ToString(Context.Items["CMB_CLASS"]);
                lstDishClass.SelectedValue = Convert.ToString(this.ViewState["CLASS"]);
            }
            if (Context.Items.Contains("CMB_TYPE"))
            {
                this.ViewState["TYPE"] = Convert.ToString(Context.Items["CMB_TYPE"]);
                lstDishType.SelectedValue = Convert.ToString(this.ViewState["TYPE"]);
            }
            if (Context.Items.Contains("CMB_KIND"))
            {
                this.ViewState["KIND"] = Convert.ToString(Context.Items["CMB_KIND"]);
                lstDishKind.SelectedValue = Convert.ToString(this.ViewState["KIND"]);
            }
            if (Context.Items.Contains("CMB_DILIVERY"))
            {
                this.ViewState["DILIVERY"] = Convert.ToString(Context.Items["CMB_DILIVERY"]);
                lstDishDelivery.SelectedValue = Convert.ToString(this.ViewState["DILIVERY"]);
            }
        }
    }

    // bind common catalog data 
    private void initPageControls()
    {
        DishDao dao = new DishDao();
        CommonDictionaryBean bean = new CommonDictionaryBean();

        // 用餐时间
        bean.Catalog = "M_DISH.DISH_TIME";
        IList lstTime = dao.FindByCatalog(bean);
        lstTime.Insert(0, new CommonDictionaryBean());
        lstDishTime.DataSource = lstTime;
        lstDishTime.DataBind();

        // 荤素类别
        bean.Catalog = "M_DISH.DISH_CLASS";
        IList lstClass = dao.FindByCatalog(bean);
        lstClass.Insert(0, new CommonDictionaryBean());
        lstDishClass.DataSource = lstClass;
        lstDishClass.DataBind();

        // 套菜类别
        bean.Catalog = "M_DISH.DISH_KIND";
        IList lstKind = dao.FindByCatalog(bean);
        lstKind.Insert(0, new CommonDictionaryBean());
        lstDishKind.DataSource = lstKind;
        lstDishKind.DataBind();

        // 菜式类别
        bean.Catalog = "M_DISH.DISH_TYPE";
        IList lstType = dao.FindByCatalog(bean);
        lstType.Insert(0, new CommonDictionaryBean());
        lstDishType.DataSource = lstType;
        lstDishType.DataBind();

        // 送菜类别
        bean.Catalog = "M_DISH.DISH_DELIVERY";
        IList lstDelivery = dao.FindByCatalog(bean);
        lstDelivery.Insert(0, new CommonDictionaryBean());
        lstDishDelivery.DataSource = lstDelivery;
        lstDishDelivery.DataBind();

    }


    // before render
    void Page_PreRender(object sender, EventArgs e)
    {
        // get current doctor responsibility members list
        DishDao dao = new DishDao();
        IList lstRst = null;
        DishBean bean = new DishBean();
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["TIME"])))
        {
            bean.DishTime = Convert.ToString(this.ViewState["TIME"]);
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["CLASS"])))
        {
            bean.DishClass = Convert.ToString(this.ViewState["CLASS"]);
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["KIND"])))
        {
            bean.DishKind = Convert.ToString(this.ViewState["KIND"]);
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["TYPE"])))
        {
            bean.DishType = Convert.ToString(this.ViewState["TYPE"]);
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["DELIVERY"])))
        {
            bean.DishDelivery = Convert.ToString(this.ViewState["DELIVERY"]);
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["NAME"])))
        {
            bean.DishName = Convert.ToString(this.ViewState["NAME"]);
        }

        lstRst = dao.ListDish(bean);
        if (lstRst.Count == 0)
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                    HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0046").ToString();
        }
        else
        {
            viewSrhRst.DataSource = lstRst;
            viewSrhRst.DataBind();
        }
    }

    // page index change
    protected void viewSrhRst_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        viewSrhRst.PageIndex = e.NewPageIndex;
    }


    protected void viewSrhRst_OnRowEditing(object sender, GridViewEditEventArgs e)
    {
        string dishId = null;
        int index = Convert.ToInt32(e.NewEditIndex);
        // Get the Key value from the GridView control.
        DataKey key = viewSrhRst.DataKeys[index];
        dishId = Convert.ToString(key.Value);
        string url = "~/App/Input/DishUpdForm.aspx";


        // 传递分页编号
        Context.Items["DISH_ID"] = dishId;
        Context.Items["ParamPageIndex"] = viewSrhRst.PageIndex;
        ControllerUtils.Transfer(Context, url, true);    
    }

    protected void viewSrhRst_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int index = Convert.ToInt32(e.RowIndex);
        // Get the Key value from the GridView control.
        DataKey key = viewSrhRst.DataKeys[index];
        int dishId = Convert.ToInt32(key.Value);

        DishDao dao = new DishDao();
        DishBean bean = new DishBean();
        bean.DishId = dishId;
        dao.DeleteDish(bean);
            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0003").ToString();

    }
    

    // details click
    protected void viewSrhRst_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    }

    // adjust bind data
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        this.ViewState["TIME"] = lstDishTime.SelectedValue;
        this.ViewState["CLASS"] = lstDishClass.SelectedValue;
        this.ViewState["TYPE"] = lstDishType.SelectedValue;
        this.ViewState["KIND"] = lstDishKind.SelectedValue;
        this.ViewState["DELIVERY"] = lstDishDelivery.SelectedValue;
        this.ViewState["NAME"] = txtDishName.Text;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        string url = "~/App/Input/PersonJobForm.aspx";

        // 传递分页编号
        Context.Items["CMB_JOB_ID"] = Convert.ToString(this.ViewState["JOB_ID"]);
        Context.Items["CMB_GROUP_ID"] = Convert.ToString(this.ViewState["GROUP_ID"]);
        Context.Items["CMB_STATUS_ID"] = Convert.ToString(this.ViewState["STATUS_ID"]);
        Context.Items["ParamPageIndex"] = viewSrhRst.PageIndex;
        ControllerUtils.Transfer(Context, url, true);    
    }

}
